package com.lzy.cloud.goods.controller;

import com.github.pagehelper.PageInfo;
import com.lzy.cloud.goods.dtos.CarRentDto;
import com.lzy.cloud.goods.dtos.CarSaleDto;
import com.lzy.cloud.goods.entity.CarRent;
import com.lzy.cloud.goods.facade.CarRentFacade;
import com.lzy.cloud.goods.request.CarRentRequest;
import com.lzy.cloud.goods.request.CarSaleRequest;
import com.lzy.cloud.goods.response.CarRentResponse;
import com.lzy.cloud.goods.response.CarSaleResponse;
import com.lzy.cloud.goods.service.carRent.CarRentService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lc
 * @version 2018/7/12
 */
@RestController
@RequestMapping("/car/rent")
public class CarRentController {

    @Autowired
    private CarRentFacade carRentFacade;

    @Autowired
    private CarRentService carRentService;

//    /**
//     * 新增车型
//     *
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/add",method = RequestMethod.POST)
//    public Result add(@RequestBody CarRentRequest request){
//        Ensure.that(request).isNotNull("00010001");
//        Boolean add = carRentFacade.add(DozerUtils.map(request, CarRentDto.class));
//        return new Result(add);
//    }

    /**
     * 分页查询房车租赁
     * @return
     */
//    @RequestMapping(value = "/find",method = RequestMethod.GET)
//    public Result findByPage(CarRentRequest request){
//        Ensure.that(request).isNotNull("00010001");
//        Pager pager = new Pager();
//        pager.setPageNum(request.getPageNum());
//        pager.setPageSize(request.getPageSize());
//        PageInfo<CarRentDto> pageInfo = carRentService.selectList(pager,DozerUtils.map(request,CarRentDto.class),null);
//        if (pageInfo != null && pageInfo.getList() != null) {
//            pager.setTotal(pageInfo.getTotal());
//            return new Result(pager,DozerUtils.maps(pageInfo.getList(), CarRentResponse.class));
//        } else {
//            return new Result();
//        }
//    }

    /**
     * 分页查询回收站房车
     * @return
     */
//    @RequestMapping(value = "/find/recycled",method = RequestMethod.POST)
//    public Result findRecycled(@RequestBody CarRentRequest request){
//        Ensure.that(request).isNotNull("00010001");
//        Pager pager = new Pager();
//        pager.setPageNum(request.getPageNum());
//        pager.setPageSize(request.getPageSize());
//        PageInfo<CarRentDto> pageInfo = carRentService.findRecycled(pager,DozerUtils.map(request,CarRentDto.class));
//        if (pageInfo != null && pageInfo.getList() != null) {
//            pager.setTotal(pageInfo.getTotal());
//            return new Result(pager,DozerUtils.maps(pageInfo.getList(), CarRentResponse.class));
//        } else {
//            return new Result();
//        }
//    }


//    /**
//     * 查看详情
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "/select-detail/{id}",method = RequestMethod.GET)
//    public Result selectById(@PathVariable("id") Long id){
//        CarRentDto carRentDto = carRentFacade.getDetail(id);
//        Ensure.that(carRentDto).isNotNull("00020004");
//        return new Result(DozerUtils.map(carRentDto, CarRentResponse.class));
//    }

//    /**
//     * 编辑车型
//     *
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/update",method = RequestMethod.PUT)
//    public Result update(@RequestBody CarRentRequest request){
//        Ensure.that(request).isNotNull("00010001");
//        return new Result(carRentFacade.update(DozerUtils.map(request, CarRentDto.class)));
//    }

//    /**
//     * 批量删除
//     * @param ids
//     * @return
//     */
//    @RequestMapping(value = "/delete/{ids}",method = RequestMethod.PUT)
//    public Result deleteById(@PathVariable("ids") String ids){
//        Ensure.that(ids).isNotNull("00010001");
//        return new Result(carRentService.deleteById(ids));
//    }

//    /**
//     *  批量恢复到仓库
//     * @param ids
//     * @return
//     */
//    @RequestMapping(value = "/recovery/{ids}",method = RequestMethod.PUT)
//    public Result recoveryById(@PathVariable("ids") String ids){
//        Ensure.that(ids).isNotNull("00010001");
//        return new Result(carRentService.recoveryById(ids));
//    }

    /**
     *  获取该商户的房车数量
     * @param shopId
     * @return
     */
    @RequestMapping(value = "/car/number/{shopId}",method = RequestMethod.POST)
    public Result getCarNumberByShopId(@PathVariable("shopId") Long shopId){
        Ensure.that(shopId).isNotNull("00010001");
        return new Result(carRentService.getCarNumberByShopId(shopId));
    }
}
